<?php
/**
 * jishupu-cms
 * @Author:技术铺
 * @Date:2021/11/22
 */

namespace App\Services;

use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;

/**
 * 系统信息模块服务层
 *
 * Class SystemInfoService
 * @package App\Services
 */
class SystemInfoService
{
    public static $phpVersion = PHP_VERSION;
    public static $softVersion = 'jishupu-cms v1.0.1';
    public static $vueVersion = '2.6.10';
    public static $elementUi = '2.15.7';

    /**
     * laravel框架版本
     * @return string
     */
    public static function getLaravel()
    {
        return app()::VERSION;
    }

    /**
     * 获取操作系统信息
     * @param string $model 默认s即获取操作系统名称
     * @return string
     */
    public static function getOs($model = 's')
    {
        return php_uname($model);
    }

    /**
     * web服务器/运行环境
     * @return array
     */
    public static function getWebServer()
    {
        return $_SERVER['SERVER_SOFTWARE'];
    }

    /**
     * 获取MYSQL数据库版本
     * @return mixed
     */
    public static function getMysqlVersion()
    {
        $v = "version()";
        return DB::select("select version()")[0]->$v;
    }

    /**
     * 上传限制
     * @return float|int
     */
    public static function getUploadSize()
    {
        return UploadedFile::getMaxFilesize();
    }

    /**
     * 获取系统信息
     * @return array[]
     */
    public static function get()
    {
        return [
            'soft' => [
                'name' => __('systemInfo.soft'),
                'desc' => self::$softVersion
            ],
            'php' => [
                'name' => __('systemInfo.php'),
                'desc' => self::$phpVersion
            ],
            'laravel' => [
                'name' => __('systemInfo.laravel'),
                'desc' => self::getLaravel()
            ],
            'vue' => [
                'name' => __('systemInfo.vue'),
                'desc' => self::$vueVersion
            ],
            'element' => [
                'name' => __('systemInfo.element'),
                'desc' => self::$elementUi
            ],
            'os' => [
                'name' => __('systemInfo.os'),
                'desc' => self::getOs()
            ],
            'webServer' => [
                'name' => __('systemInfo.webServer'),
                'desc' => self::getWebServer()
            ],
            'database' => [
                'name' => __('systemInfo.database'),
                'desc' => 'Mysql ' . self::getMysqlVersion()
            ],
            'uploadSize' => [
                'name' => __('systemInfo.uploadSize'),
                'desc' =>  @ini_get('file_uploads') ? ini_get('upload_max_filesize') :'unknown'
            ],
        ];
    }


}
